package crawler.torunski;

import com.torunski.crawler.Crawler;
import com.torunski.crawler.filter.BeginningPathFilter;
import com.torunski.crawler.model.ICrawlerModel;
import com.torunski.crawler.model.MaxDepthModel;
import com.torunski.crawler.model.MaxIterationsModel;

import crawler.LinkFilterRepository;

public class TorunskiIterationCrawler implements ITorunskiCrawler {
	
	private static final String ACCEPT_LIST = "/";
	private String _server;
	private String _start;
	private long _maxLinks;

	private LinkFilterRepository _repository;

	public TorunskiIterationCrawler(String server, String start, long maxLinks, LinkFilterRepository repository){
		_server = server;
		_start = start;
		_repository = repository;
		_maxLinks = maxLinks;
		java.util.logging.LogManager.getLogManager().reset();
	}
	

	@Override
	public void crawl() {
		Crawler crawler = new Crawler();
		ICrawlerModel model = new MaxIterationsModel((int)_maxLinks);
		if(_maxLinks<=0) model = new MaxDepthModel(2); 
        crawler.setModel(model);
        crawler.setLinkFilter(new BeginningPathFilter(ACCEPT_LIST));
        crawler.addLoadingListener(new URLLoadingListener(_repository, _server));
        crawler.start(_server, _start);        
	}









}
